mobileFX WebKitX ActiveX
WebKitX JavaScript Externs~-_namespace / SQLXGetSchema Method
SQLX connection string of the database to open.
Name of the Schema information to retrieve: TABLES, VIEWS, COLUMNS, FOREIGN_KEYS.
Comma separated key-value pairs or null.
Callback function to execute when data are fetched.
Object context that receives the callback
In This Topic
    SQLXGetSchema Method
    In This Topic
    SQLXGetSchema, opens a database connection, executes an SQL statement and returns the data in JSON format. This function uses commercial SQLX driver.

    Opens a database connection, queries its Schema and returns the data in JSON format.

    Syntax
    var value; // Type: boolean
    
    // Parameters
    var ConnectionString; // Type:  string
    var SchemaEnum; // Type:  string
    var KeyValuePairs; // Type:  string
    var CallbackFunction; // Type:  any
    var ThisContext; // Type:  object
    
    value = SQLXGetSchema(ConnectionString,
                          SchemaEnum,
                          KeyValuePairs,
                          CallbackFunction,
                          ThisContext);
    function SQLXGetSchema( 
       ConnectionString : string,
       SchemaEnum : string,
       KeyValuePairs : string,
       CallbackFunction : any,
       ThisContext : object
    ) : boolean;

    Parameters

    ConnectionString
    SQLX connection string of the database to open.
    SchemaEnum
    Name of the Schema information to retrieve: TABLES, VIEWS, COLUMNS, FOREIGN_KEYS.
    KeyValuePairs
    Comma separated key-value pairs or null.
    CallbackFunction
    Callback function to execute when data are fetched.
    ThisContext
    Object context that receives the callback
    Example
    function ExecSQL(SQL)
    {
    	var db = db_connection_string();
    	var ab = SQLXExecSQL(db, SQL, "ArrayBuffer", function(ab)
    	{
    		var ds = new Dataset;
    		ds.openFromArrayBuffer(ab);
    		LoadDatasetToGrid(ds, w2ui["x-w2ui-sql-grid"]);
    		__delete__(ds);
    	});
    }
    
    function LoadDatasetToGrid(ds, grid)
    {
    	// Reset grid
    	var columns = [];
    	var records = [];		
    
    	columns.push({			
    		field: "recid",
    		hidden: true
    	});
    
    	// Create grid coluns from dataset fields
    	for (var i = 0; i < ds.fieldCount; i++)
    	{
    		var f = ds.fieldByIndex(i);
    		var id = f.ID.replace(/[\W\s]/g, "_");
    		columns.push({
    			caption: f.NAME,
    			field: id,
    			size: "100px",
    		});
    	}
    			
    	// Create grid records from dataset records
    	ds.moveFirst();
    	var r = 0;
    	while (!ds.DB_EOF)
    	{
    		var record = { recid: ++r };		
    		for (var i = 0; i < ds.fieldCount; i++)
    		{
    			var f = ds.fieldByIndex(i);
    			var id = f.ID.replace(/[\W\s]/g, "_");
    			record[id] = f.value;
    		}
    		records.push(record);
    		ds.moveNext();
    	}
    	
    	grid.clear();
    	grid.columns = columns;
    	grid.records = records;
    	grid.refresh();
    }
    Browser Compatibility
    80